<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商户后台</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="__PUBLIC__/admin/favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
</head>
<include file="Admin@Index:cache"/>
<body class="gray-bg contacts">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-content">
                    <h2>子账号管理<a style="float:right;margin:0 1rem" class="btn btn-info" href="javascript:void(0);"
                                onclick="add_admin()">添加账号</a></h2>

                    <div class="col-sm-12" style="margin-bottom: 1rem">
                        <form role="form" action="__SELF__" method="get">
                            <div class="form-group">
                                <!--<label>商品code</label>-->
                                <input type="text" id="content" placeholder="请输入手机号" name="content"
                                       class="form-control">
                            </div>
                            <div>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit" id="search">
                                    <strong>搜索</strong>
                                </button>
                            </div>
                        </form>
                    </div>
                    <br>
                    <table class="table table-striped table-hover">
                        <tbody>
                        <tr>
                            <th>账号</th>
                            <th>角色</th>
                            <th class="">姓名</th>
                            <th> 手机号</th>
                            <th class="">状态</th>
                            <th>创建时间</th>
                            <th class="client-status">操作</th>
                        </tr>
                        <foreach name="list" item="list">
                            <tr>
                                <td><{$list.account}></td>
                                <td><{$list.rolename}></td>
                                <td><{$list.name}></td>
                                <td><{$list.mobile}></td>
                                <td>
                                    <switch name="list.state">
                                        <case value="1">启动</case>
                                        <case value="2">禁止</case>
                                    </switch>
                                </td>
                                <td class=""><{$list.ctime}></td>
                                <td class="client-status">
                                    <a class="btn btn-success btn-rounded modify" href="javascript:void(0);"
                                       onclick="modify_admin('<{$list.id}>','<{$list.account}>','<{$list.name}>','<{$list.mobile}>','<{$list.email}>','<{$list.qq}>','<{$list.rid}>','<{$list.is_hide}>','<{$list.nickname}>')">修改</a>
                                    <a class="btn btn-info btn-rounded" onclick="reset_pwd('<{$list.id}>')"
                                       href="javascript:void(0);">重置密码</a>

                                    <if condition="$list['state'] eq '1'">
                                    <a class="btn btn-warning btn-rounded" onclick="forbid_admin('<{$list.id}>','2')"
                                       href="javascript:void(0);">禁止</a>
                                    <else/>
                                        <a class="btn btn-primary btn-rounded" onclick="forbid_admin('<{$list.id}>','1')"
                                           href="javascript:void(0);">解禁</a>
                                    </if>
                                    <a class="btn btn-danger btn-rounded" onclick="del_admin('<{$list.id}>')"
                                       href="javascript:void(0);">删除</a>
                                </td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                    <ul class="pagination">
                        <if condition="$tol gt 10">
                            <{$fpage}>
                        </if>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>

<script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>

<style>
    .ii{
        width: 8%;
        height: 1.5rem;
    }
    .ss{
        font-size: 15px;
        margin: 0 15px 0px 1px;
    }
</style>
<script>
    $(document).ready(function () {
        $('.contact-box').each(function () {
            animationHover(this, 'pulse');
        });
    });

    function add_admin() {
        var role = '<{$role}>';
        var html = '';
        html += '<div class="modal-body" id="lists" style="height:100%">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" ><span style="color:red">*</span>账号：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="account" autocomplete="off" placeholder="账号" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" ><span style="color:red">*</span>密码：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="password" id="pwd" autocomplete="new-password" placeholder="密码" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" ><span style="color:red">*</span>姓名：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="name" autocomplete="off" placeholder="姓名" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" ><span style="color:red">*</span>手机号：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="mobile" autocomplete="off" placeholder="手机号" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >邮箱地址：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="email" autocomplete="abc" placeholder="邮箱地址" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >QQ号码：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="number" id="qq" autocomplete="off" placeholder="QQ号码" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >昵称：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="nickname" autocomplete="off" placeholder="客服角色专用" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >选择角色：</label>';
        html += '<div class="col-sm-8">';
//        html += '<select class="form-control m-b" name="rid" id="rid" style="height:3rem">';
        $(eval('(' + role + ')')).each(function (k, v) {
            html += '<input class="ii" value="' + v.id + '" type="checkbox"><sapn class="ss" style="margin-right: 5px" >' + v.rolename + '</sapn>';
        });
//        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >数据隐私：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="checkbox" id="privacy" style="width: 10%; float: left;height: 2rem;" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="add_admins();" type="button" class="btn btn-primary" >添加</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['500px', '620px'],
            title: '添加子账号',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }

    function add_admins() {
        layer.confirm('是否确定添加？', function () {
            var rid='';
            $("input:checkbox[class=ii]:checked").each(function(i){
                if(0==i){
                    rid+= $(this).val();
                }else{
                    rid+= (","+$(this).val());
                }
            });
            if(rid==''){
                layer.msg('请选择先角色', {time: 1000, icon: 5});
                return false;
            }
            layer.load(2);
            $.post('__MODULE__/Systems/add_admin', {
                account: $('#account').val(),
                pwd: $('#pwd').val(),
                name: $('#name').val(),
                mobile: $('#mobile').val(),
                email: $('#email').val(),
                qq: $('#qq').val(),
                nickname: $('#nickname').val(),
                rid: rid,
                privacy:document.getElementById("privacy").checked===true?2:1
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

    function modify_admin(id, account, name, mobile, email, qq, rid,privacy,nickname) {
        var role = '<{$role}>';
        var html = '';
        html += '<div class="modal-body" id="lists" style="height:100%">';
        html += '<form class="form-horizontal">';

        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" ><span style="color:red">*</span>姓名：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="name" value="' + name + '" placeholder="姓名" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" ><span style="color:red">*</span>手机号：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="mobile" value="' + mobile + '" placeholder="手机号" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >邮箱地址：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="email" value="' + email + '" placeholder="邮箱地址" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >QQ号码：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="number" id="qq" value="' + qq + '" placeholder="QQ号码" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >昵称：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="nickname"  value="' + nickname + '" autocomplete="off" placeholder="客服角色专用" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >选择角色：</label>';
        html += '<div class="col-sm-8">';
        var roles=rid.split(',');

        $(eval('(' + role + ')')).each(function (k, v){
            var s='';
            if(roles.indexOf(v.id)!='-1'){
                s='checked';
            }
            html += '<input class="ii" value="' + v.id + '" '+s+' type="checkbox"><sapn class="ss" style="margin-right: 5px" >' + v.rolename + '</sapn>';
        });
        html += '</div>';
        html += '</div>';
        var p='';
        if(privacy=='2'){
            var p='checked';
        }
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >数据隐私：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="checkbox" id="privacy" '+p+' style="width: 10%; float: left;height: 2rem;" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="modify_admins(\'' + id + '\')" type="button" class="btn btn-primary" >修改</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['500px', '480px'],
            title: '修改账户信息',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }

    function modify_admins(id) {
        layer.confirm('是否确定修改？', function () {
            var rid='';
            $("input:checkbox[class=ii]:checked").each(function(i){
                if(0==i){
                    rid+= $(this).val();
                }else{
                    rid+= (","+$(this).val());
                }
            });
            layer.load(2);
            $.post('__MODULE__/Systems/modify_admin', {
                id: id,
                name: $('#name').val(),
                mobile: $('#mobile').val(),
                email: $('#email').val(),
                qq: $('#qq').val(),
                nickname: $('#nickname').val(),
                rid: rid,
                privacy:document.getElementById("privacy").checked===true?2:1
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }


    function forbid_admin(aid, status) {
        if (status == '2') {
            var s = '是否确定禁止该账号?';
        } else {
            var s = '是否确定对该账号解除禁止?';
        }
        layer.confirm(s, function () {
            layer.load(2);
            $.post('__MODULE__/Systems/forbid_admin', {aid: aid,status:status}, function (data) {
                layer.closeAll();
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

    function reset_pwd(aid) {
        layer.confirm('是否确定重置密码', function () {
            layer.load(2);
            $.post('__MODULE__/Systems/reset_pwd', {aid: aid}, function (data) {
                layer.closeAll();
                if (data.code == '1001') {
                    layer.alert(data.result);
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

    function del_admin(aid) {
        layer.confirm('是否确定删除？', function () {
            layer.load(2);
            $.post('__MODULE__/Systems/del_admin', {aid: aid}, function (data) {
                layer.closeAll();
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

</script>


</body>

</html>
